package com.victor.bookretail.controller;

import com.victor.bookretail.domain.OrderInfoBo;
import com.victor.bookretail.domain.OrderInfoSearchBo;
import com.victor.bookretail.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

@Api
@RestController
public class OrderController {

    @Resource
    private OrderService orderService;

    @ApiOperation(value = "Create order")
    @PostMapping("/order")
    public OrderInfoBo createOrder(@Valid @RequestBody OrderInfoBo orderInfoBo) {
        return orderService.createOrder(orderInfoBo);
    }

    @ApiOperation(value = "Get order list by user id")
    @GetMapping("/order/list")
    public List<OrderInfoBo> getOderList(@NotNull @RequestParam(name = "userId") Long userId) {
        OrderInfoSearchBo searchBo = new OrderInfoSearchBo().setUserId(userId);
        return orderService.queryOrderList(searchBo);
    }
}
